package com.zch.pilot.controller;

import com.zch.domain.Result;
import com.zch.pilot.service.TbPilotProjectService;
import com.zch.pilot.vo.SearchVo;
import com.zch.pilot.vo.PilotVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
* @description: TODO
* @author 试验项目
* @date 2023/10/30 20:07
* @version 1.0
*/
@RestController
@RequestMapping("/pilot")
public class PilotController {
    @Autowired
    private TbPilotProjectService tbPilotProjectService;

    /**
     * @description: TODO 删除
     * @author 王志赛
     * @date 2023/10/30 21:43
     * @version 1.0
     */
    @PostMapping("/deletedByID")
    public Result deletedByID(@RequestBody PilotVo pilotVo){
        return tbPilotProjectService.deletedByID(pilotVo);
    }

    /**
     * @description: TODO 添加
     * @author 王志赛
     * @date 2023/10/30 21:45
     * @version 1.0
     */
    @PostMapping("/save")
    public Result save(@RequestBody PilotVo pilotVo){
        return tbPilotProjectService.addPilot(pilotVo);
    }

    /**
     * @description: TODO 修改
     * @author 王志赛
     * @date 2023/10/31 8:20
     * @version 1.0
     */
    @PostMapping("/update")
    public Result update(@RequestBody PilotVo pilotVo){
        return tbPilotProjectService.updateAll(pilotVo);
    }

    @PostMapping("/select")
    public Result select(@RequestBody PilotVo pilotVo){
        return tbPilotProjectService.selectByPilot(pilotVo);
    }

    /**
    * @description: TODO 导入文件数据
    * @author 韩国焘
    * @date 2023/10/31 10:45
    * @version 1.0
    */
    @PostMapping("/importDataByFile")
    public Result importData(MultipartFile file){
        return tbPilotProjectService.importData(file);
    }

    /**
    * @description: TODO 导出excel
    * @author 韩国焘
    * @date 2023/10/31 10:45
    * @version 1.0
    */
    @GetMapping("/exportExcelFile")
    public Result exportExcelFile(@RequestBody List<PilotVo> list, HttpServletResponse response){
        return tbPilotProjectService.exportExcelFile(list,response);
    }

    /**
    * @description: TODO 分页+试验项目名称精准查询
    * @author 韩国焘
    * @date 2023/10/31 11:18
    * @version 1.0
    */
    @PostMapping("/listByPage")
    public Result listByPage(@RequestBody SearchVo searchVo){
        return tbPilotProjectService.listByPage(searchVo);
    }
}
